package com.xingchi.tornado.mybatisplus.config;

import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
import com.xingchi.tornado.unique.provider.impl.SnowflakeProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 自定义id生成器
 *
 * @author xingchi
 * @date 2024/5/28 13:51
 */
@Component
public class CustomIdGenerator implements IdentifierGenerator {

    @Autowired
    private SnowflakeProvider snowflakeProvider;

    /**
     * 生成Id
     *
     * @param entity 实体
     * @return id
     */
    @Override
    public Number nextId(Object entity) {
        return snowflakeProvider.nextId();
    }
}
